<?php
/**
* Class Almacen.
*
* Implementation of the class Permiso.
*
* PHP version >= 5.1
*
* @category     FrameworkPunkuPHP
* @package      Model
* @author       Juan Carlos Torrico Rios
* @copyright    2010 Juan Carlos Torrico Rios
* @license      http://creativecommons.org/licenses/by/3.0/legalcode  Creative Commons License Attribution 3.0 Unported
* @version      1.0
* @link         None
* @see          None
* @since        Available from the version  0.1 01-01-2010
* @deprecated   No
*/

/**
* Class Almacen
*
* Implementation of class Permiso.
*
* @category   WindowSI
* @package    Model
* @author     Juan Carlos Torrico Rios
* @copyright  2010 Juan Carlos Torrico Rios
* @license    http://creativecommons.org/licenses/by/3.0/legalcode  Creative Commons License Attribution 3.0 Unported
* @version    1.0
* @link       None
* @see        None
* @since      Available from the version  0.1 01-01-2010
* @deprecated No
*/
    class Almacen {
     // {{{ Constants

    /**
     * Constant for represent all registers.
     *
     * @access private
     */
     const ALL = -1;
     const VALUE = 1;
     const NONE = 0;
     // Operations
     const INSERT = "INSERT TABLE ALM_ALMACEN";
     const UPDATE = "UPDATE TABLE ALM_ALMACEN";
     const DELETE = "DELETE TABLE ALM_ALMACEN";
     const SELECT = "SELECT TABLE ALM_ALMACEN";
    // }}}

    // {{{ atributos

    /**
     * Variable instance Data Base.
     *
     * @var DataBase
     * @access private
     */
        private  $instanceDataBase;
    // }}}

    // {{{ constructores

    /**
     * This is construct base of the class.
     *
     * A public constructor; initializes the variable $instanceDataBase.
     *
     */
        public function __construct( $instanceDataBase ) {
            $this->instanceDataBase = $instanceDataBase;
        }
    // }}}

    // {{{ metodos

    /**
     * The implementation method for query to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function getListAlmacen($idAlmacen = self::ALL){
            $result = null;
            $query = null;
            try{
                $query = "SELECT    pk_id_almacen ,
                                    cod_almacen ,
                                    almacen ,
                                    descripcion ,
                                    fk_id_grupo ,
                                    fk_id_sistema_valoracion_inventario ,
                                    fecha_transaccion ,
                                    usuario_transaccion ,
                                    estado_registro ,
                                    transaccion_creacion ,
                                    transaccion_modificacion,
                                    fk_id_empresa 
                           FROM   alm_almacen 
                           WHERE  estado_registro = 'A' ";

                if( $idAlmacen != self::ALL){
                $query = $query." AND pk_id_almacen = ?";
                $result = DataBase::getArrayListQuery($query, array($idAlmacen), $this->instanceDataBase);
                }
                else{
                $result = DataBase::getArrayListQuery($query,array(), $this->instanceDataBase);
                }
            }
            catch(PDOException $e){
                echo 'Error JF-Model-0941: '.$e->getMessage();
            }
            return $result;
        }

    /**
     * The implementation method for insert data to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function insertAlmacen($data){
            $result = null;
            $query = null;
            try{
                $query = "INSERT INTO 
                                alm_almacen( 	                                                                       	
                                    cod_almacen ,
                                    almacen ,
                                    descripcion ,
                                    fk_id_grupo ,
                                    fk_id_sistema_valoracion_inventario ,
                                    fecha_transaccion ,
                                    usuario_transaccion ,
                                    estado_registro ,
                                    transaccion_creacion ,
                                    transaccion_modificacion,
                                    fk_id_empresa  ) ".
                         "VALUES ( ?, ?, ?, ?, ?, current_timestamp(), ?, 'A', ?, ?, ?)";
                DataBase::getBeginTransaction($this->instanceDataBase);
                $result = DataBase::getExecuteDML($query, $data,$this->instanceDataBase);
                DataBase::getCommitTransaction($this->instanceDataBase);
            }
            catch(PDOException $e){
                echo 'Error JF-Model-0932: '.$e->getMessage();
            }
            return $result;
        }

     /**
     * The implementation method for delete data to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function deleteAlmacen($data){
            $result = null;
            $query = null;
            try{
                $query = "UPDATE alm_almacen ".
                         "SET estado_registro = 'E', ".
                         "    transaccion_modificacion = ?, fecha_transaccion = current_timestamp(), usuario_transaccion = ? ".
                         "WHERE pk_id_almacen = ? ";
                DataBase::getBeginTransaction($this->instanceDataBase);
                $result = DataBase::getExecuteDML($query, $data,$this->instanceDataBase);
                DataBase::getCommitTransaction($this->instanceDataBase);

            }
            catch(PDOException $e){
                echo 'Error JF-Model-0943: '.$e->getMessage();
            }
            return $result;
        }

     /**
     * The implementation method for update data to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function updateAlmacen($data){
            $result = null;
            $query = null;
            try{
                $query = "UPDATE alm_almacen ".
                         "SET cod_almacen = ?,
                                almacen = ?,
                                descripcion = ?,
                                fk_id_grupo = ?,
                                fk_id_sistema_valoracion_inventario  = ?,  ".
                         "    transaccion_modificacion = ?, fecha_transaccion = current_timestamp(), usuario_transaccion = ?, fk_id_empresa= ?".
                         "WHERE pk_id_almacen = ? ";

                DataBase::getBeginTransaction($this->instanceDataBase);
                $result = DataBase::getExecuteDML($query, $data,$this->instanceDataBase);
                DataBase::getCommitTransaction($this->instanceDataBase);
            }
            catch(PDOException $e){
                echo 'Error JF-Model-0944: '.$e->getMessage();
            }
            return $result;
        }
     // }}}
    }
?>